package com.chinairi.mall.service.impl;

import com.chinairi.common.utils.UserSession;
import com.chinairi.mall.controller.viewobject.ServiceTypeClassVO;
import com.chinairi.mall.error.BusinessException;
import com.chinairi.mall.error.EmBusinessError;
import com.chinairi.mall.model.ServiceTypeClass;
import com.chinairi.mall.dao.ServiceTypeClassMapper;
import com.chinairi.mall.service.IServiceTypeClassService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chinairi.mall.service.modelobject.ServiceTypeClassMO;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务分类表 服务实现类
 * </p>
 *
 * @author Webgasd
 * @since 2020-09-16
 */
@Service
public class ServiceTypeClassServiceImpl extends ServiceImpl<ServiceTypeClassMapper, ServiceTypeClass> implements IServiceTypeClassService {
    @Autowired
    private ServiceTypeClassMapper serviceTypeClassMapper;

    /**
     * 根据大类id获取小类列表
     *
     * @param serviceType 大类id
     * @return ServiceTypeClassVO
     */
    @Override
    public ServiceTypeClassVO getServiceTypeClassListByServiceType(String serviceType) {
        List<ServiceTypeClassMO> resultList;
        if (serviceType == null||"".equals(serviceType)||"qwe01".equals(serviceType)|| "qwe02".equals(serviceType)|| "qwe06".equals(serviceType)){
            resultList = serviceTypeClassMapper.getServiceTypeClassListByServiceType(UserSession.getUserId(), serviceType,0);
        }
        else {
            resultList = serviceTypeClassMapper.getServiceTypeClassListByServiceType(UserSession.getUserId(), serviceType,1);
        }
        if (resultList.size() == 0) {
            throw new BusinessException(EmBusinessError.PARAMETER_VALIDATION_ERROR, "您的企业未签订相关的服务框架协议，请检查后重试！");
        }
        ServiceTypeClassVO serviceTypeClassVO = new ServiceTypeClassVO();
        serviceTypeClassVO.setContDbid(resultList.get(0).getContDbid());
        serviceTypeClassVO.setComaContractName(resultList.get(0).getComaContractName());
        serviceTypeClassVO.setStSerTypeDbid(resultList.get(0).getStSerTypeDbid());
        serviceTypeClassVO.setStSerType(resultList.get(0).getStSerType());
        serviceTypeClassVO.setServiceTypeClassMOList(resultList);
        return serviceTypeClassVO;
    }
}
